import os
import sys
import codecs

def search_sjis_string(directory, target_str):
    for root, _, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            try:
                with open(file_path, 'rb') as f:
                    content = f.read()
                    if target_str.encode('sjis') in content:
                        print(f'在文件 {file_path} 中找到匹配！')
            except Exception as e:
                print(f'处理文件 {file_path} 时出现错误：{e}')

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print('请提供目录路径和要搜索的SJIS编码字符串作为参数。')
        print('示例: python search_sjis.py ~/SMT4CN/ フーリン')
    else:
        target_directory = sys.argv[1]
        target_str = sys.argv[2]
        search_sjis_string(target_directory, target_str)

